<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 200px;
            height: 200px;
            background-color: yellow;
        }
    </style>
</head>
<body>
<div></div>
<script>
    
        // 创建日期对象,当前时间
//         const date = new Date();
//         console.log(date);
// // 指定时间
// const date1 = new Date("2021-08-01 10:00:00");
// console.log(date1);
// // 格式化日期
// const date2 = new Date("2021-08-01 10:00:00");
// const year = date2.getFullYear();
// const month = date2.getMonth() + 1;
// const day = date2.getDate();
// const hour = date2.getHours();
// const minute = date2.getMinutes();
// const second = date2.getSeconds();
// console.log(`${year}-${month}-${day} ${hour}:${minute}:${second}`);
const div =document.querySelector(
    'div'
)
function getMyDate(){
    const date = new Date();
    let h = date.getHours();
    let m = date.getMinutes();
    let s = date.getSeconds();
    m = m<10?'0'+m:m;
    s = s<10?'0'+s:s;
    h = h<10?'0'+h:h;
    return `今天是：${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()} 号${h}`;
    }
    div.innerHTML = getMyDate();
    </script>
</body>
</html>